import Toast from "@vant/weapp/toast/toast"
Page({
  /**
   * 页面的初始数据
   */
  data: {
    initData: {} as Room,
    startTime: "",
    endTime: "",
    price: 0.0,
    userName: "",
    number: null,
    tips: "",
  },
  init() {
    let { start, end } = getApp().globData
    let startTime = start.format("M月D日")
    let endTime = end.format("M月D日")
    let days = end.diff(start, "day")
    let price = getApp().globData.roomOrder.price
    let initData = getApp().globData.roomOrder.info
    this.setData({
      startTime,
      endTime,
      days,
      price,
      initData,
    })
  },
  infoChange(e: any) {
    let name = e.currentTarget.dataset.name
    let value = e.detail
    if (name == "name") {
      this.setData({
        userName: value,
      })
    }
    if (name == "number") {
      this.setData({
        number: value,
      })
    }
    if (name == "tips") {
      this.setData({
        tips: value,
      })
    }
  },
  payfor() {
    let userName = this.data.userName
    let number = this.data.number
    let tips = this.data.tips
    let roomId = this.data.initData.id
    if (number && userName) {
      getApp().globData.userInfo = { userName, number, tips, roomId }
      wx.navigateTo({
        url: "/pages/pay/pay",
      })
    } else {
      Toast.fail("信息不完整")
    }
  },
  onShow() {
    this.init()
  },
})
